<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <jsp:include page="../common/header.jsp" flush="true"/>
</head>
<body>

<jsp:include page="../common/noHeader.jsp" flush="true"/>

<div class="row" style="margin: 60px 0px;">
    <img src="../assets/image/banner_news.jpg" width="100%" height="auto"/>
</div>



<section class="container">
    <div class="row">
        <div class="col-sm-12" style="padding: 10px 0px;">
            <a href="/newEdit/forward"><button class="btn btn-success">新增</button></a>
        </div>
        <div class="box-tools">
            <form action="list" method="post">
                <div class="input-group pull-right" style="width: 250px;">
                    <input type="text" name="keyword" value="${page.keyword}" class="form-control input-sm " placeholder="标题">
                    <div class="input-group-btn ">
                        <button class="btn btn-default input-sm " type="submit"><i class="fa fa-search"></i></button>
                    </div>
                </div>
            </form>
        </div>
        <table class="table table-striped table-bordered">
            <thead>
            <tr>
                <th>类型</th>
                <th>创建时间</th>
                <th>标题</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
                <c:forEach items="${page.allentities}" var="list" varStatus="vs">
                <tr>
                    <td data-label="类型">
                        <c:choose>
                            <c:when test="${list.type == 0}">
                                新闻
                            </c:when>
                            <c:otherwise>
                                活动
                            </c:otherwise>
                        </c:choose>
                    </td>
                    <td data-label="创建时间">${list.createTime}</td>
                    <td data-label="标题">
                        <c:choose>
                            <c:when test="${list.top == 1}">
                                <b style="color: red">[置顶]</b>
                            </c:when>
                        </c:choose>
                        ${list.newsTitle}
                    </td>
                    <td data-label="状态">
                        <c:choose>
                            <c:when test="${list.status == 0}">
                                未发布
                            </c:when>
                            <c:otherwise>
                                已发布
                            </c:otherwise>
                        </c:choose>
                    </td>
                    <td data-label="操作">
                        <button class="btn btn-success" onclick="change(${list.id},${list.status})">
                            <c:choose>
                                <c:when test="${list.status == 0}">
                                    发布
                                </c:when>
                                <c:otherwise>
                                    取消发布
                                </c:otherwise>
                            </c:choose>
                        </button>
                        <button class="btn btn-success" onclick="changeTop(${list.id},${list.top})">
                            <c:choose>
                                <c:when test="${list.top == 0}">
                                    置顶
                                </c:when>
                                <c:otherwise>
                                    取消置顶
                                </c:otherwise>
                            </c:choose>
                        </button>
                        <a href="/newEdit/forward?id=${list.id}&mode=1"><button class="btn btn-success">编辑</button></a>
                        <a href="/news/forward?id=${list.id}&mode=1" target="_blank"><button class="btn btn-success">查看</button></a>
                        <button class="btn btn-danger" onclick="del(${list.id})">删除</button>
                    </td>
                </tr>
                </c:forEach>
            </tbody>
        </table>
    </div>

    <jsp:include page="../common/page.jsp" flush="true"/><!--动态包含-->
</section>

<jsp:include page="../common/footer.jsp" flush="true"/>

</body>
</html>
<link rel="stylesheet" href="/assets/css/postbirdAlertBox.min.css">
<script src="/assets/js/postbirdAlertBox.min.js"></script>
<script>
    function del(newId) {
        var id=newId;
        PostbirdAlertBox.confirm({
            'title': '删除操作',
            'content': '你确定删除该新闻信息吗',
            'okBtn': '确定',
            'contentColor': 'red',
            'onConfirm': function () {
                window.location.href="/newEdit/delete?id="+id;
            },
            'onCancel': function () {
            }
        });
    }

    function change(newId,status) {
        var id=newId;
        var msg;
        if(status == 0){
            msg = "你确定要发布该新闻吗"
        }else{
            msg = "你确定要取消发布该新闻吗"
        }
        PostbirdAlertBox.confirm({
            'title': '操作',
            'content': msg,
            'okBtn': '确定',
            'contentColor': 'red',
            'onConfirm': function () {
                window.location.href="/newEdit/change?id="+id;
            },
            'onCancel': function () {
            }
        });
    }

    function changeTop(newId,top) {
        var id=newId;
        var msg;
        if(top == 0){
            msg = "你确定要置顶该新闻吗"
        }else{
            msg = "你确定要取消置顶该新闻吗"
        }
        PostbirdAlertBox.confirm({
            'title': '操作',
            'content': msg,
            'okBtn': '确定',
            'contentColor': 'red',
            'onConfirm': function () {
                window.location.href="/newEdit/changeTop?id="+id;
            },
            'onCancel': function () {
            }
        });
    }
</script>
